package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    public void work(BookList bookList){
        //添加图书
        System.out.println("添加图书！");
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入你要查找的图书的名字：");
        String name = scanner.nextLine();

        System.out.println("请输入你要查找的图书的作者：");
        String author = scanner.nextLine();

        System.out.println("请输入你要查找的图书的价格：");
        int price = scanner.nextInt();

        scanner.nextLine(); //会读取输入价格后的换行符，所以加上此行避免下面输入类型的代码读取换行符

        System.out.println("请输入你要查找的图书的类型：");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);
        //1.获取当前书的位置
        int currentSize = bookList.getUsedSize();
        //2.把书放置到当前指定的位置
        bookList.setBooks(book, currentSize);
        //3.书的有效个数+1
        bookList.setUsedSize(currentSize+1);

    }
}
